package GUILayer;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import java.awt.Color;

import javax.swing.border.TitledBorder;
import java.awt.GridLayout;
import java.util.ArrayList;

import ModelLayer.Employee;

public class TimeList extends JPanel 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel pnlList;
	private TimeListItem selectedItem;
	private BookingPanel parent;
	
	public TimeList()
	{
		
	}
	
	public TimeList(BookingPanel parent) 
	{
		setBorder(new TitledBorder(null, "Ledige tider", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setLayout(null);
		setSize(510, 300);
		
		pnlList = new JPanel();
		pnlList.setBorder(new LineBorder(Color.LIGHT_GRAY));
		pnlList.setBackground(Color.WHITE);
		pnlList.setBounds(10, 19, 490, 270);
		pnlList.setLayout(new GridLayout(1, 4));
		add(pnlList);
		
		selectedItem = null;
		
		this.parent = parent;
	}
	
	public void addListItems(ArrayList<Employee> emps)
	{
		pnlList.removeAll();
		
		selectedItem = null;
		
		for(Employee emp : emps)
		{
			TimeListItem item = new TimeListItem(emp);
			
			pnlList.add(item);
		}
	}
	
	public void removeAllItems()
	{
		pnlList.removeAll();
		pnlList.repaint();
	}
	
	public void setSelectedItem(TimeListItem item)
	{
		this.selectedItem = item;
		
		parent.updateTreatEmployee();
		parent.updateStartTime();
		//parent.updateDate();
	}
	
	public TimeListItem getSelectedItem()
	{
		return selectedItem;
	}
}
